import service from '@/utils/request'

// @Summary 用户登录
// @Produce  application/json
// @Param data body {username:"string",password:"string"}
// @Router /base/login [post]
export const login = (data) => {
  return new Promise((resolve,reject)=>{
    service.post('/boss/login',data)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// @Summary 用户登出
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"登出成功"}"
// @Router /base/logout [post]
export const logout = (data) => {
  return new Promise((resolve,reject)=>{
    service.get('/boss/logout')
    .then(res=>{
      resolve(res.data) 
    })
  })
}



// @Summary 修改密码
// @Produce  application/json
// @Param data body {username:"string",password:"string",newPassword:"string"}
// @Router /user/updateUserPassword [post]
export const updateUserPassword = (data) => {
  return service({
    url: '/user/updateUserPassword',
    method: 'post',
    data: data
  })
}


export const getCouseList = (params) => { // 获取绿色能量列表
  return new Promise((resolve,reject)=>{
    service.post('/admin/course/list',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getUserList = (params) => { // 获取用户列表
  return new Promise((resolve,reject)=>{
    service.post('/admin/user/list',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getRoleList = (params) => { // 获取角色列表
  return new Promise((resolve,reject)=>{
    service.post('/boss/role/listManager',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const addRole = (params) => { // 新增角色
  return new Promise((resolve,reject)=>{
    service.post('/boss/role/insert',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const editRole = (params) => { // 编辑角色
  return new Promise((resolve,reject)=>{
    service.post('/boss/role/update',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const delRole = (roleId) => { // 删除角色
  return new Promise((resolve,reject)=>{
    service.get(`boss/role/delete/${roleId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getRoleDetail = (roleId) => { // 获取角色详情
  return new Promise((resolve,reject)=>{
    service.get(`/boss/role/get/${roleId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getAuthTree = () => { // 获权限树
  return new Promise((resolve,reject)=>{
    service.get('/boss/permission/rootTree')
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getAccountList = (params) => { // 获取帐号列表
  return new Promise((resolve,reject)=>{
    service.post('/boss/account/listManager',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const addAccount = (params) => { // 添加帐号
  return new Promise((resolve,reject)=>{
    service.post('/boss/account/insert',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const editAccount = (params) => { // 编辑帐号
  return new Promise((resolve,reject)=>{
    service.post('/boss/account/update',params)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

export const getAccountDetail = (userId) => { // 获取帐号详情
  return new Promise((resolve,reject)=>{
    service.get(`/boss/account/get/${userId}`)
    .then(res=>{
      resolve(res.data) 
    })
  })
}

// export const delAccount = (roleId) => { // 删除角色
//   return new Promise((resolve,reject)=>{
//     service.get(`boss/role/delete/${roleId}`)
//     .then(res=>{
//       resolve(res.data) 
//     })
//   })
// }



// @Tags SysUser
// @Summary 删除用户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SetUserAuth true "删除用户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/deleteUser [post]
export const deleteUser = (data) => {
  return service({
    url: '/user/deleteUser',
    method: 'post',
    data: data
  })
}

// @Tags SysUser
// @Summary 设置用户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysUser true "设置用户信息"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/saveUser [put]
export const saveUser = (data) => {
  return service({
    url: '/user/saveUser',
    method: 'post',
    data: data
  })
}

// @Tags User
// @Summary 设置用户权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.saveUserRoleList true "设置用户权限"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/saveUserRoleList [post]
export const saveUserRoleList = (data) => {
  return service({
    url: '/user/saveUserRoleList',
    method: 'post',
    data: data
  })
}

// @Tags User
// @Summary 获取用户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /user/getUserInfo [get]
export const getUserInfo = () => {
  return service({
    url: '/user/getUserInfo',
    method: 'get'
  })
}

export const resetUserPassword = (data) => {
  return service({
    url: '/user/resetUserPassword',
    method: 'post',
    data: data
  })
}
